<%@page import="my.db.DTO.AuthenticationDTO"%>
<%@page import="my.db.DTO.AuthorDTO"%>
<%@ include file="sites/ad_header.jsp" %>
<%
	if(session.getAttribute("user") ==null){
		response.sendRedirect("LoadIndex.jsp");
	}
%>
<%
AuthenticationDTO author=(AuthenticationDTO)request.getAttribute("read_author");
if(author!=null){
%>
<div class="r-body">
	<div class="page-title">
		<p>Update Author Information</p>
	</div>
	
	<div class="frm-action">
					<form action="./update_author.article?author_id=<%=author.getAutDTO().getAuthorID() %>" method="post" >
					<table border="0" cellpadding="10">
						<tr>
							<td><a href="javascript:history.go(-1);"><img src="Image/go_back.png" class="go_back" title="Back to Main page"/></td>
							<td></td>
						</tr>
						<tr>
							<td width="150">Full Name</td>
							<td>: <input type="text"  value="<%=author.getAutDTO().getAuthorName() %>"  name="userName" class="userName" required="required"></td>
						</tr>
						
						<tr>									
							<td>Gender</td>
							<td>: 
							<select name="userGender" class="userGender"/>
								<%
									if(author.getAutDTO().getAuthorGender()==0){
								%>
									<option value="1">Male</option>
									<option value="0" selected="selected">Female</option>
								<%
									}else{
								%>
									<option value="1" selected="selected">Male</option>
									<option value="0">Female</option>
								<% 
									}
								%>
									
								  </select>
							</td>
						</tr>
						<tr>
									<td>User Email</td>
									<td>: <input type="text" required="required" value="<%=author.getAutDTO().getAuthorMail() %>" name="userMail" class="userMail"></td>
						</tr>
						<tr>
									<td>Phone</td>
									<td>: <input type="text" required="required"  value="<%=author.getAutDTO().getAuthorPhone() %>" name="userPhone" class="userPhone"></td>
						</tr>
			
						<tr>
							
							<td style="text-align:right;"><input type="submit" value="SAVE" class="btn-default" style="width:100px; margin-left:0px;"/></td>
							<td><input type="button" value="Change Password" class="cmd-change-pass" style="width:170px; margin-left:0px;"/></td>
						</tr>
					</table>
					</form>
					<!-- Update Account -->
					<form action="./update_account.article?accountID=<%=author.getAccountID() %>" method="post">			
								<table border="0" cellpadding="10" class="tb-update-pass-author">
									<tr>
										<td>Old Password</td>
										<td>New Password</td>
										<td>Confirm Password</td>
										<td><input type="submit"   name="update_pass"  class="update_pass" value="update" onclick="updatePwd()" /></td>
									</tr>
									
									<tr>
										<td><input type="text" readonly="readonly"  name="pwd" placeholder="old password" value="<%=author.getAccountPassword()%>"/></td>
										<td><input type="password" required="required" class="npwd" name="npwd" placeholder="new password"/></td>
										<td><input type="password" required="required" class="cpwd" name="cpwd" placeholder="confirm password"/></td>
										<td><input type="button" name="update" id="updatePwd" value="Cencel" class="cmd-pass-cencel"/></td>
									</tr>
								</table>	
					</form>
				</div>
</div>
<%} %>
<style type="text/css">
	.hide-tb{display:none;}
</style>
<script type="text/javascript">
	$(function(){
		$(".tb-update-pass-author").addClass("hide-tb");
		$(".cmd-change-pass").click(function(){
			$(".tb-update-pass-author").removeClass("hide-tb");
		});
		
		$(".cmd-pass-cencel").click(function(){
			$(".tb-update-pass-author").addClass("hide-tb");
		});
		
		$(".update_pass").click(function(){		
			var pass=$(".npwd").val();
			var conf=$(".cpwd").val();
			if(pass==conf){
				return true;
			}else{
				alert("Confirm password doesn't match! try again.");
				$(".cpwd").val("");
				return false;
			} 
		});
	});
</script>
